import Storage from 'vue-ls'
import vueBus from './utils/vueBus'
import moment from 'moment'
import components from './components/index.js'
import ApiList from './apilist'
import changeSystem from './utils/changeSystem'
import { filter } from './utils/filter'
import { RyListMixin } from './mixins/RyListMixin'
import { CommonModal } from './mixins/CommonModal'
import DataDict from './utils/dataDict'
import apiManage from './api/manage.js'

export {
  ApiList,
  RyListMixin,
  CommonModal
}


/** 注册全局组件 */
export default {
  install (Vue, store, router, process) {
    Vue.use(changeSystem, router, 'Token')
    /**常用过滤 */
    Vue.use(filter)

    /**浏览器缓存 */
    Vue.use(Storage, {
      namespace: 'pro__', // key prefix
      name: 'ls', // name variable Vue.[ls] or this.[$ls],
      storage: 'local' // storage name session, local, memory
    })
    /**vuebus注册 */
    Vue.use(vueBus)

    /**时间格式化 */
    moment.locale('zh-cn')
    Vue.prototype.moment = moment

    /**全局注册组件 */
    Vue.use(components)

    window.$store = store

    /** 注册数据字典公共方法 */
    Vue.use(DataDict)

    /**注册axios请求方法 */
    Vue.use(apiManage, store, process)

    /**请求成功判断 */
    window.isSuccess = Vue.prototype.isSuccess = function (res) {
      return res.code === 0 || res.code === 200 || res.success === true
    }
    /**数据类型判定 */
    window._UTILS = {
      isArray: function isArray (obj) {
        return Object.prototype.toString.call(obj) === '[object Array]'
      },

      isObject: function isObject (obj) {
        return Object.prototype.toString.call(obj) === '[object Object]'
      },

      isString: function isString (obj) {
        return Object.prototype.toString.call(obj) === '[object String]'
      },

      isNumber: function isNumber (obj) {
        return Object.prototype.toString.call(obj) === '[object Number]'
      },

      isFunction: function isFunction (obj) {
        return Object.prototype.toString.call(obj) === '[object Function]'
      },

      isEmptyObject: function isEmptyObject (o) {
        return JSON.stringify(o) === '{}'
      },

      isEmptyArray: function emptyArray (o) {
        return JSON.stringify(o) === '[]'
      }
    }
  }
}